package com.quicklife.service.impl;

import net.sf.json.JSONObject;

import com.quicklife.service.inter.WebCheckService;
import com.quicklife.util.JsonUtil;
import com.quicklife.util.SqlHelper;
import com.quicklife.util.StringUtil;

/**
 * web注册实时验证
 * 
 * 
 * @author HackerD
 * 
 */
public class WebCheckServiceImpl implements WebCheckService {

	@Override
	public String checkInfoByRealTime(String rqinfos) {
		try {
			JSONObject jsonObject = JSONObject.fromObject(rqinfos);
			String colname = jsonObject.getString("colname");
			String colvalue = jsonObject.getString("colvalue");

			String sql = "business where " + colname + "=?";
			String rtInfos = SqlHelper.checkBeExist(sql, new String[]{colvalue}, null);
			if (rtInfos == null) {
				return JsonUtil
						.createRtJsonStr(StringUtil.RESULT_CODE_OK, null);
			} else {
				return JsonUtil.createRtJsonStr(StringUtil.RESULT_CODE_FAIL,
						null);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return JsonUtil.createRtJsonStr(StringUtil.RESULT_CODE_FAIL,
					StringUtil.RESULT_EXCEPTION);
		}
	}

	@Override
	public String checkPswByRealTime(String rqinfos) {
		try {
			JSONObject jsonObject = JSONObject.fromObject(rqinfos);
			String id = jsonObject.getString("userid");
			String psw = jsonObject.getString("password");

			String sql = "business where password=? and id=?";
			String rtInfos = SqlHelper.checkBeExist(sql, new String[]{psw,id}, null);

			if (rtInfos == null) {
				return JsonUtil
						.createRtJsonStr(StringUtil.RESULT_CODE_FAIL, null);
			} else {
				return JsonUtil.createRtJsonStr(StringUtil.RESULT_CODE_OK,
						null);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return JsonUtil.createRtJsonStr(StringUtil.RESULT_CODE_FAIL,
					StringUtil.RESULT_EXCEPTION);
		}
	}

}
